package sms;

import java.io.IOException; 
import java.util.Calendar;
import java.util.Date; 
 
import org.jsmpp.InvalidResponseException; 
import org.jsmpp.PDUException; 
import org.jsmpp.bean.Alphabet; 
import org.jsmpp.bean.BindType; 
import org.jsmpp.bean.ESMClass; 
import org.jsmpp.bean.GeneralDataCoding; 
import org.jsmpp.bean.MessageClass; 
import org.jsmpp.bean.NumberingPlanIndicator; 
import org.jsmpp.bean.RegisteredDelivery; 
import org.jsmpp.bean.SMSCDeliveryReceipt; 
import org.jsmpp.bean.TypeOfNumber; 
import org.jsmpp.extra.NegativeResponseException; 
import org.jsmpp.extra.ResponseTimeoutException; 
import org.jsmpp.session.BindParameter; 
import org.jsmpp.session.SMPPSession; 
import org.jsmpp.util.AbsoluteTimeFormatter; 
import org.jsmpp.util.TimeFormatter; 
 
/** 
 * @author uudashr 
 * 
 */ 
public class SMS { 
    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();; 
     
    public static void main(String[] args) { 
        SMPPSession session = new SMPPSession(); 
        try { 
            session.connectAndBind("smsc5.routotelecom.com", 7777, new BindParameter(BindType.BIND_TRX, "1172461", "m6wwh5x4", "SMS", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null)); 
            System.out.println("da ket moi");
        } catch (IOException e) { 
            System.err.println("Failed connect and bind to host"); 
            e.printStackTrace(); 
        } 
         
        try {
        	System.out.println("sdhsjsdgh " + timeFormatter.format(Calendar.getInstance()));
            String messageId = session.submitShortMessage("SMS", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "447781470665", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "84986477141", new ESMClass(), (byte)0, (byte)1,  timeFormatter.format(Calendar.getInstance()), null, new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT), (byte)0,new GeneralDataCoding(false,false, MessageClass.CLASS1,Alphabet.ALPHA_DEFAULT), (byte)0, "em iu oi dang test sms gateway".getBytes()); 
            //session.submitShortMessage(serviceType, sourceAddrTon, sourceAddrNpi, sourceAddr, destAddrTon, destAddrNpi, destinationAddr, esmClass, protocolId, priorityFlag, scheduleDeliveryTime, validityPeriod, registeredDelivery, replaceIfPresentFlag, dataCoding, smDefaultMsgId, shortMessage, optionalParameters);
            System.out.println("Message submitted, message_id is " + messageId); 
        } catch (PDUException e) { 
            // Invalid PDU parameter 
            System.err.println("Invalid PDU parameter"); 
            e.printStackTrace(); 
        } catch (ResponseTimeoutException e) { 
            // Response timeout 
            System.err.println("Response timeout"); 
            e.printStackTrace(); 
        } catch (InvalidResponseException e) { 
            // Invalid response 
            System.err.println("Receive invalid respose"); 
            e.printStackTrace(); 
        } catch (NegativeResponseException e) { 
            // Receiving negative response (non-zero command_status) 
            System.err.println("Receive negative response"); 
            e.printStackTrace(); 
        } catch (IOException e) { 
            System.err.println("IO error occur"); 
            e.printStackTrace(); 
        } 
         
        session.unbindAndClose(); 
    } 
     
     
} 


